package com.wyc.servicePassengerUser.controller;

import java.util.List;

import com.wyc.internalCommon.request.VerificationCodeDTO;
import com.wyc.internalCommon.result.ApiResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RestController;
import com.wyc.servicePassengerUser.dto.PassengerUser;
import com.wyc.servicePassengerUser.service.PassengerUserService;

/**
 * 乘客用户Controller
 * 
 * @author li
 * @date 2023-03-21
 */
@RestController
public class PassengerUserController
{
    @Autowired
    private PassengerUserService passengerUserService;

    /**
     * 查询乘客用户列表
     */
    @GetMapping("/list")
    public ApiResult list(PassengerUser passengerUser)
    {
        List<PassengerUser> list = passengerUserService.selectPassengerUserList(passengerUser);
        return ApiResult.success(list);
    }

    /**
     * 获取乘客用户详细信息
     */
    @GetMapping(value = "/{id}")
    public ApiResult getInfo(@PathVariable("id") Long id)
    {
        return ApiResult.success(passengerUserService.selectPassengerUserById(id));
    }

    /**
     * 新增乘客用户
     */
    @PostMapping("/add")
    public ApiResult add(@RequestBody PassengerUser passengerUser)
    {
        return ApiResult.success(passengerUserService.insertPassengerUser(passengerUser));
    }

    /**
     * 修改乘客用户
     */
    @PutMapping("/update")
    public ApiResult edit(@RequestBody PassengerUser passengerUser)
    {
        return ApiResult.success(passengerUserService.updatePassengerUser(passengerUser));
    }

    /**
     * 删除乘客用户
     */
	@DeleteMapping("/{ids}")
    public ApiResult remove(@PathVariable Long[] ids)
    {
        return ApiResult.success(passengerUserService.deletePassengerUserByIds(ids));
    }

    /**
     * 根据手机号查询是否存在该乘客，不存在新增
     * @return
     */
    @PostMapping("/user")
    public ApiResult loginOrReg(@RequestBody VerificationCodeDTO verificationCodeDTO){
        return passengerUserService.loginOrReg(verificationCodeDTO);
    }

    /**
     * 根据手机号查询乘客信息
     * @return
     */
    @GetMapping ("/user/{phone}")
    public ApiResult getUserByPhone(@PathVariable("phone") String passengerPhone){
        return passengerUserService.getUserByPhone(passengerPhone);
    }
}
